using System;

namespace Sedge.Core.Utils
{
	public class ViewManager : IViewManager
	{
		private bool _isLocked;
		private BreakedLockHandler _breakedLockHandler;

		public event LockingEventHandler LockingChanged;
		public bool IsLocked
		{
			get { return _isLocked; }
		}

		public bool CleanOnExit { get; set; }

		public void LockView(BreakedLockHandler breakedLockHandler)
		{
			_breakedLockHandler = breakedLockHandler;
			_isLocked = true;

			if (LockingChanged != null)
				LockingChanged(true);
		}

		public void UnlockView()
		{
			_isLocked = false;

			if (LockingChanged != null)
				LockingChanged(false);
		}

		public void BreakLock()
		{
			if (_breakedLockHandler != null)
				_breakedLockHandler();

			UnlockView();
		}
	}
}